﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StockFinder.Model;
using StockFinder.Services.Brokers;
using log4net;

namespace StockFinder.Services.StockListFilter.IBD
{
    public class BreakoutStockListFilter : IIBDStockListFilter
    {
        private static readonly ILog _Log = LogManager.GetLogger(typeof(BreakoutStockListFilter));

        private List<string> _Stocks = new List<string>();

        public bool FilterPriceAnalysisResult(PriceAnalysisResult priceAnalysisResult, IBDRatings ibdRatings)
        {
            bool result = false;

            if (priceAnalysisResult.BaseLength >= 16 &&
                    priceAnalysisResult.BaseDepth <= 30 &&
                    ibdRatings.IBDComposite >= 85 &&
                    ibdRatings.EPS >= 70 &&
                    ibdRatings.RelativeStrength >= 85 &&
                    priceAnalysisResult.DepthFromAllTimeHigh <= 4)
            {
                _Log.DebugFormat("Added '{0}' to BreakoutStockListFilter", priceAnalysisResult.SymbolName);

                _Stocks.Add(ibdRatings.Symbol);

                result = true;
            }

            return result;
        }

        public void UpdateServerList()
        {
            var broker = new IBDStockListBroker();
            broker.UpdateStockList(_Stocks, 413598973756058, "Breakout");
        }
    }
}
